﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace CMS.Common.Validation
{
    public enum ZipCodeType
    {
        /// <summary>
        /// FiveDigits
        /// </summary>
        FiveDigits,

        /// <summary>
        /// TenDigits
        /// </summary>
        TenDigits
    }

    public class ZipCodeAttribute : RegularExpressionAttribute, IClientValidatable
    {
        public ZipCodeAttribute()
            : base(@"^(\d{5}-\d{4}|\d{5})$")
        {
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRegexRule(ErrorMessage, Pattern);
            rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
            return new[] { rule };
        }
    }
}